package com.whty.cms.filewps.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class Pagination implements Serializable {
	
	private static final long serialVersionUID = 1L;

    private Integer curPage = 1; //当前页

    private Integer numPerPage = 10; // 每页数量

    private Integer totalCount = 0; // 总数

    private Integer totalPage = 0; // 总页数
    
    private Integer curCount=0;//当前数量

    private List<Integer> pagesGroup = null; // 分页

    public List<Integer> getPagesGroup() {
        return pagesGroup;
    }

    public void setPagesGroup(List<Integer> pagesGroup) {
        this.pagesGroup = pagesGroup;
    }

    public Integer getFirstRow() {
        return ((getCurPage() - 1) * getNumPerPage()) + 1;
    }

    public Integer getLastRow() {
        Integer lastRow = getCurPage() * getNumPerPage();
        return (lastRow > getTotalCount()) ? getTotalCount() : lastRow;
    }

    public List<Integer> getPageGroup() {
        int basePage;
        if (getCurPage() < 5) {
            basePage = 0;
        } else {
            basePage = getCurPage() - 5;
        }
        List<Integer> pageGroup = new ArrayList<>();
        int num = getTotalPage() - basePage;
        num = num >= 9 ? 9 : num;
        for (int i = 1; i <= 9; i++) {
            if ((basePage - (9 - num) + i) > 0) {
                pageGroup.add(basePage - (9 - num) + i);
            }
        }
        return pageGroup;
    }

    public Integer getCurPage() {
        if (curPage <= 0) {
            curPage = 1;
        } else if (curPage > getTotalPage() && getTotalPage() > 0) {
            curPage = totalPage;
        }
        return curPage;
    }

    public void setCurPage(Integer curPage) {
        this.curPage = curPage;
    }

    public Integer getNumPerPage() {
        if (numPerPage <= 0)
            numPerPage = 10;
        return numPerPage;
    }

    public void setNumPerPage(Integer numPerPage) {
        this.numPerPage = numPerPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        if (totalCount == 0) {
            totalPage = 0;
        } else {
            if (totalCount % numPerPage == 0) {
                totalPage = (totalCount / numPerPage);
            } else {
                totalPage = (totalCount / numPerPage) + 1;
            }
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Pagination() {
        super();
    }

    public Pagination(Integer curPage, Integer numPerPage) {
        super();
        this.curPage = curPage;
        this.numPerPage = numPerPage;
    }
    
    public Integer getCurCount() {
        return (getCurPage()-1)*getNumPerPage();
    }

    public void setCurCount(Integer curCount) {
        this.curCount = curCount;
    }
	
}
